package org.testis.gui.mvc.utilities;

import java.util.HashMap;
import javax.swing.ImageIcon;

/**
 *
 * @author Cahit Emir Erel
 */
public class ImageFactory {
    private static ImageFactory reference;
    private static HashMap<String,ImageIcon> imageMap = new HashMap<String,ImageIcon>();
    private ImageFactory() {
        
    }
    public static ImageFactory instance() {
        if (reference==null) {
            reference = new ImageFactory();
        }
        return reference;
    }

    public ImageIcon createImageIcon(String path)
    {
        ImageIcon icon = imageMap.get(path);
        if (icon!=null) {
            return icon;
        }
        java.net.URL imgURL = MyTreeRenderer.class.getResource(path);
        if (imgURL != null) {
            icon = new ImageIcon(imgURL);
            imageMap.put(path,
                         icon);
            return icon;
        }
        else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
}
